package com.yidu.t299.dao.cfj;

import com.yidu.t299.domain.cfj.Record;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RecordMapper {
    /**
     * 根据编号删除信息
     * @param recordId 编号
     * @return 影响的行数(返回1则为成功)
     */
    @Delete({
            "delete from record" +
                    " where record_id = #{record_id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer recordId);

    /**
     * 添加信息
     * @param record
     * @return 影响的行数(返回1则为成功)
     */
    @Insert({
            "insert into record (record_id, record_name,record_age,record_sex,record_phone,record_email,record_address,record_id_card,dept_id,job_id,record_salary,record_school,school_id,record_degree,agree_job_date,just_job_date,dimission_date)" +
                    " values (#{recordId,jdbcType=INTEGER}, #{recordName,jdbcType=VARCHAR}," +
                    "#{recordAge,jdbcType=INTEGER},#{recordSex,jdbcType=VARCHAR}," +
                    "#{recordPhone,jdbcType=VARCHAR},#{recordEmail,jdbcType=VARCHAR}," +
                    "#{recordAddress,jdbcType=VARCHAR},#{recordIdCard,jdbcType=VARCHAR}," +
                    "#{deptId,jdbcType=INTEGER},#{jobId,jdbcType=INTEGER}," +
                    "#{recordSalary,jdbcType=VARCHAR},#{recordSchool,jdbcType=VARCHAR}," +
                    "#{schoolId,jdbcType=INTEGER},#{recordDegree,jdbcType=VARCHAR}," +
                    "#{agreeJobDate,jdbcType=VARCHAR},#{justJobDate,jdbcType=VARCHAR}," +
                    "#{dimissionDate,jdbcType=VARCHAR})"
    })
    int insert(Record record);

    /**
     * 根据编号查询指定的信息
     * @param recordId
     * @return
     */
    @Select({
            "select" +
                    " record_id, record_name,record_salary,agree_job_date" +
                    " from record" +
                    " where record_id = #{recordId,jdbcType=INTEGER}"
    })
    @Results(id = "RecordMap",value = {
            @Result(id = true,column = "record_id",property = "recordId"),
            @Result(column = "record_name",property = "recordName"),
            @Result(column = "record_salary",property = "recordSalary"),
            @Result(column = "agree_job_date",property = "agreeJobDate")
    })
    Record selectByPrimaryKey(Integer recordId);

    /**
     * 按条件分页查询校区数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 对象集合
     */
    @Select("select * from (select record_id,record_name,record_address,record_salary,agree_job_date from record) r where 1=1 ${condition} limit #{page},#{rows}")
    @ResultMap("RecordMap")
    List<Record> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询表中数据行数
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from (select record_id,record_name,record_address,record_salary,agree_job_date from record) r where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据信息修改其数据
     * @param record
     * @return 影响的行数(返回1则为成功)
     */
    @Update({
            "update record",
            " set record_name = #{recordName,jdbcType=VARCHAR}," +
            " record_age = #{recordAge,jdbcType=INTEGER}," +
            " record_sex = #{recordSex,jdbcType=VARCHAR}," +
            " record_phone = #{recordPhone,jdbcType=VARCHAR}," +
            " record_email = #{recordEmail,jdbcType=VARCHAR}," +
            " record_address = #{recordAddress,jdbcType=VARCHAR}," +
            " record_id_card = #{recordIdCard,jdbcType=VARCHAR}," +
            " dept_id = #{deptId,jdbcType=INTEGER}," +
            " job_id = #{jobId,jdbcType=INTEGER}," +
            " record_salary = #{recordSalary,jdbcType=VARCHAR}," +
            " record_school = #{recordSchool,jdbcType=VARCHAR}," +
            " school_id = #{schoolId,jdbcType=INTEGER}," +
            " record_degree = #{recordDegree,jdbcType=VARCHAR}," +
            " agree_job_date = #{agreeJobDate,jdbcType=VARCHAR}," +
            " just_job_date = #{justJobDate,jdbcType=VARCHAR}," +
            " dimission_date = #{dimissionDate,jdbcType=VARCHAR}" +
            " where record_id = #{jobId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Record record);

    @Select("select record_id from record where record_name = #{recordName,jdbcType=VARCHAR}")
    int selectByName(String recordName);
}